
import { MongooseFactory } from "../kalend";
import { Schema } from "mongoose";

// 坐标信息
const locationSchema = MongooseFactory.ChildSchema({
    lat: {
        type: Number
    },
    lng: {
        type: Number
    }
});
// 城市信息
const addressSchema = MongooseFactory.ChildSchema({
    adcode: {
        type: Number
    },
    province: {
        type: String
    },
    city: {
        type: String
    },
    district: {
        type: String
    }
});

//县
const countyschema = MongooseFactory.Schema({
  //县编码
  adcode: {
      type: String
  },
  //县名称
  countyname: {
      type: String
  },
  //坐标
  location: {
      type: locationSchema
  },
  
});

/** 城市表 */
const schema = MongooseFactory.Schema({
    createuser: {
        type: Schema.Types.ObjectId,
        ref: "platform_user"
    },
    modifyuser: {
        type: Schema.Types.ObjectId,
        ref: "platform_user"
    },
    modifytime: {
        type: Date
    },
    location: {
        type: locationSchema
    },
    ad_info: {
        type: addressSchema
    },
    // 类型 1：省会城市 2：普通城市 
    type:{
        type: Number,
        default: 1
    },
    // 状态 1：有效 0：禁用
    status:{
        type: Number,
        default: 1
    },
    //排序
    order:{
      type:Number,
      default: 9999
    },
    //县
    childcountry:{
      type:[countyschema]
    }
});



export const cityinfoModel = MongooseFactory.Model("cityinfo", schema);